package com.yanqu.road.server.cmd.activity.unionwar;

import com.yanqu.road.pb.activity.unionwar.UnionWarActivityServerProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.unionwar.UnionWarActivityModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

import java.util.List;

@Cmd(code = GameProtocol.S_UNION_WAR_ACTIVITY_GUESS, desc = "群英争霸竞猜")
public class UnionWarActivityGuessCmd extends AbstractCommand {
    private int activityId;
    private int stage;
    private List<UnionWarActivityServerProto.UnionWarGuessDataTemp> unionUid;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        UnionWarActivityServerProto.UnionWarGuessReqMsg msg = UnionWarActivityServerProto.UnionWarGuessReqMsg.parseFrom(packet.getBytes());
        activityId = msg.getActivityId();
        stage = msg.getStage();
        unionUid = msg.getUnionList();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(UnionWarActivityModule.class).guess(activityId, unionUid, stage);
    }

    @Override
    public void sendData(GamePlayer player) {
        UnionWarActivityServerProto.UnionWarGuessRespMsg.Builder respMsg = UnionWarActivityServerProto.UnionWarGuessRespMsg.newBuilder();
        respMsg.setRet(ret);
        player.sendPacket(ClientProtocol.U_UNION_WAR_ACTIVITY_GUESS, respMsg);
    }
}
